package com.esri.core.tasks.geodatabase;

import com.esri.core.internal.util.d;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonToken;

/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes.dex */
public class SyncProcessRecoveryInfo {
    private static final String ACKNOWLEDGED_UPLOAD_FIELD = "acknowledgedUpload";
    private static final String CLIENT_DELTA_PATH_FIELD = "clientDeltaPath";
    private static final String CREATED_CLIENT_DELTA_FIELD = "createdClientDelta";
    private static final String SYNC_COMPLETE_FIELD = "syncComplete";
    private static final String SYNC_STATUS_URL_FIELD = "syncStatusUrl";
    private static final String UPLOADED_CLIENT_DELTA_FIELD = "uploadedClientDelta";
    private static final String UPLOAD_ID_FIELD = "uploadId";
    private boolean _acknowledgedUpload;
    private String _clientDeltaPath;
    private boolean _createdClientDelta;
    private File _recoveredStatusFile;
    private boolean _syncComplete;
    private String _syncStatusUrl;
    private String _uploadId;
    private boolean _uploadedClientDelta;

    public SyncProcessRecoveryInfo(File file) throws Exception {
        this._recoveredStatusFile = file;
        if (file != null) {
            if (file.exists()) {
                FileInputStream fileInputStream = new FileInputStream(file);
                fromJson(d.a((InputStream) fileInputStream));
                fileInputStream.close();
                return;
            }
            File parentFile = file.getParentFile();
            if (parentFile.exists()) {
                return;
            }
            parentFile.mkdirs();
        }
    }

    public void setUploadClientDeltaDone(String str) {
        this._uploadId = str;
        this._createdClientDelta = true;
        this._uploadedClientDelta = true;
        updateFile();
    }

    public boolean createdClientDelta() {
        return this._createdClientDelta;
    }

    public void setCreatedClientDelta(String str) {
        this._clientDeltaPath = str;
        this._createdClientDelta = true;
        updateFile();
    }

    public String getClientDeltaPath() {
        return this._clientDeltaPath;
    }

    public boolean uploadClientDeltaDone() {
        return this._uploadedClientDelta;
    }

    public String getUploadId() {
        return this._uploadId;
    }

    public boolean acknowledgedUpload() {
        return this._acknowledgedUpload;
    }

    public void setAcknowledgedUpdload() {
        this._acknowledgedUpload = true;
        updateFile();
    }

    public boolean syncComplete() {
        return this._syncComplete;
    }

    public void setSyncComplete(String str) {
        this._syncComplete = true;
        this._syncStatusUrl = str;
        updateFile();
    }

    public void setSyncFailed() {
        this._syncComplete = false;
        this._syncStatusUrl = null;
        updateFile();
    }

    public String getSyncStatusUrl() {
        return this._syncStatusUrl;
    }

    public void cleanupRecoveryInfo() {
        File parentFile = this._recoveredStatusFile.getParentFile();
        if (parentFile == null || !parentFile.exists() || Thread.currentThread().isInterrupted()) {
            return;
        }
        File[] listFiles = parentFile.listFiles();
        if (listFiles != null) {
            for (File file : listFiles) {
                file.delete();
            }
        }
        parentFile.delete();
    }

    /* JADX WARN: Removed duplicated region for block: B:25:0x0033  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    private void updateFile() {
        /*
            r4 = this;
            r0 = 0
            java.io.PrintStream r1 = new java.io.PrintStream     // Catch: java.lang.Throwable -> L14 java.io.IOException -> L19 java.io.FileNotFoundException -> L23
            java.io.File r2 = r4._recoveredStatusFile     // Catch: java.lang.Throwable -> L14 java.io.IOException -> L19 java.io.FileNotFoundException -> L23
            r1.<init>(r2)     // Catch: java.lang.Throwable -> L14 java.io.IOException -> L19 java.io.FileNotFoundException -> L23
            java.lang.String r0 = r4.toJson()     // Catch: java.io.IOException -> L10 java.io.FileNotFoundException -> L12 java.lang.Throwable -> L30
            r1.print(r0)     // Catch: java.io.IOException -> L10 java.io.FileNotFoundException -> L12 java.lang.Throwable -> L30
            goto L2c
        L10:
            r0 = move-exception
            goto L1d
        L12:
            r0 = move-exception
            goto L27
        L14:
            r1 = move-exception
            r3 = r1
            r1 = r0
            r0 = r3
            goto L31
        L19:
            r1 = move-exception
            r3 = r1
            r1 = r0
            r0 = r3
        L1d:
            r0.printStackTrace()     // Catch: java.lang.Throwable -> L30
            if (r1 == 0) goto L2f
            goto L2c
        L23:
            r1 = move-exception
            r3 = r1
            r1 = r0
            r0 = r3
        L27:
            r0.printStackTrace()     // Catch: java.lang.Throwable -> L30
            if (r1 == 0) goto L2f
        L2c:
            r1.close()
        L2f:
            return
        L30:
            r0 = move-exception
        L31:
            if (r1 == 0) goto L36
            r1.close()
        L36:
            throw r0
        */
        throw new UnsupportedOperationException("Method not decompiled: com.esri.core.tasks.geodatabase.SyncProcessRecoveryInfo.updateFile():void");
    }

    private void fromJson(JsonParser jsonParser) throws Exception {
        if (d.c(jsonParser)) {
            while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
                String currentName = jsonParser.getCurrentName();
                jsonParser.nextToken();
                if (currentName.equals(UPLOAD_ID_FIELD)) {
                    this._uploadId = jsonParser.getText();
                } else if (currentName.equals(CLIENT_DELTA_PATH_FIELD)) {
                    this._clientDeltaPath = jsonParser.getText();
                } else if (currentName.equals(CREATED_CLIENT_DELTA_FIELD)) {
                    this._createdClientDelta = jsonParser.getBooleanValue();
                } else if (currentName.equals(UPLOADED_CLIENT_DELTA_FIELD)) {
                    this._uploadedClientDelta = jsonParser.getBooleanValue();
                } else if (currentName.equals(ACKNOWLEDGED_UPLOAD_FIELD)) {
                    this._acknowledgedUpload = jsonParser.getBooleanValue();
                } else if (currentName.equals(SYNC_COMPLETE_FIELD)) {
                    this._syncComplete = jsonParser.getBooleanValue();
                } else if (currentName.equals(SYNC_STATUS_URL_FIELD)) {
                    this._syncStatusUrl = jsonParser.getText();
                } else {
                    jsonParser.skipChildren();
                }
            }
        }
    }

    private String toJson() throws IOException {
        StringWriter stringWriter = new StringWriter();
        JsonGenerator a = d.a(stringWriter);
        a.writeStartObject();
        a.writeStringField(UPLOAD_ID_FIELD, this._uploadId);
        a.writeStringField(CLIENT_DELTA_PATH_FIELD, this._clientDeltaPath);
        a.writeBooleanField(CREATED_CLIENT_DELTA_FIELD, this._createdClientDelta);
        a.writeBooleanField(UPLOADED_CLIENT_DELTA_FIELD, this._uploadedClientDelta);
        a.writeBooleanField(ACKNOWLEDGED_UPLOAD_FIELD, this._acknowledgedUpload);
        a.writeBooleanField(SYNC_COMPLETE_FIELD, this._syncComplete);
        a.writeStringField(SYNC_STATUS_URL_FIELD, this._syncStatusUrl);
        a.writeEndObject();
        a.close();
        return stringWriter.toString();
    }
}
